]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
screenshot: Return error when stream creation fails
authorFlorian Müllner <fmuellner@gnome.org>
Tue, 24 Mar 2020 06:44:31 +0000 (07:44 +0100)
committerCarlos Garnacho <mrgarnacho@gmail.com>
Tue, 24 Mar 2020 11:29:53 +0000 (11:29 +0000)
The Shell.Screenshot API expects valid output streams for writing the
completed screenshot, not NULL.

Handle this properly by returning an error instead of passing it on
to the screenshot.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1123

js/ui/screenshot.js

index 09f5c5109fb24b2bc9d03866dd86e9b3898f9555..78afc4ae47b3f2f04ab2f3e323034046ef383bef 100644 (file)
@@ -84,7 +84,7 @@ var ScreenshotService = class {
         }
     }
 
-    _createStream(filename) {
+    _createStream(filename, invocation) {
         if (filename == '')
             return [Gio.MemoryOutputStream.new_resizable(), null];
 
@@ -94,6 +94,7 @@ var ScreenshotService = class {
                 let stream = file.replace(null, false, Gio.FileCreateFlags.NONE, null);
                 return [stream, file];
             } catch (e) {
+                invocation.return_value(GLib.Variant.new('(bs)', [false, '']));
                 return [null, null];
             }
         }
@@ -104,10 +105,11 @@ var ScreenshotService = class {
                 return [stream, file];
             } catch (e) {
                 if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.EXISTS))
-                    return [null, null];
+                    break;
             }
         }
 
+        invocation.return_value(GLib.Variant.new('(bs)', [false, '']));
         return [null, null];
     }
 
@@ -169,7 +171,9 @@ var ScreenshotService = class {
         if (!screenshot)
             return;
 
-        let [stream, file] = this._createStream(filename);
+        let [stream, file] = this._createStream(filename, invocation);
+        if (!stream)
+            return;
 
         screenshot.screenshot_area(x, y, width, height, stream,
             (o, res) => {
@@ -190,7 +194,9 @@ var ScreenshotService = class {
         if (!screenshot)
             return;
 
-        let [stream, file] = this._createStream(filename);
+        let [stream, file] = this._createStream(filename, invocation);
+        if (!stream)
+            return;
 
         screenshot.screenshot_window(includeFrame, includeCursor, stream,
             (o, res) => {
@@ -211,7 +217,9 @@ var ScreenshotService = class {
         if (!screenshot)
             return;
 
-        let [stream, file] = this._createStream(filename);
+        let [stream, file] = this._createStream(filename, invocation);
+        if (!stream)
+            return;
 
         screenshot.screenshot(includeCursor, stream,
             (o, res) => {